package org.blade.personal.utils.upload.concre;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.FileUtils;
import org.blade.personal.utils.upload.FileUploador;

public class ConcreFileUploador implements FileUploador {

	/**
	 * 判断文件存在
	 * @param filePath
	 * @return
	 */
	private boolean isFileExisted(String filePath) {

		boolean exists = false;
		File file = new File(filePath);
		if(file.exists()){
			exists = true;
		}
		return exists;
	}
	
	
	@Override
	public void ensureFileExisted(String filePath) {
		if(isFileExisted( filePath)){
			return;
		}
		File file = new File(filePath);
		file.mkdirs();
	}

	@Override
	public void writeToFile(InputStream in, String filePath) {
		ensureFileExisted(filePath);
		try {
			// 创建文件目
			FileUtils.copyInputStreamToFile(in,
					new File(filePath));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
